The SharedAudioSession interface provides a convenient way to manage and interact with the shared audio session in your script. The audio session acts as an intermediary between your script, the Scripting app, the operating system, and the underlying audio hardware, enabling you to configure and control audio behavior effectively.
categoryGet the current audio session category.
categoryOptionsRetrieve the current audio session category options.
setCategory(category: AudioSessionCategory, options: AudioSessionCategoryOptions[])Set the audio session category with specific options.
modeRetrieve the current audio session mode.
setMode(mode: AudioSessionMode)Set the audio session mode.
preferredSampleRateRetrieve the preferred sample rate in hertz.
setPreferredSampleRate(sampleRate: number)Set the preferred sample rate for audio input and output.
addInterruptionListener(listener: AudioSessionInterruptionListener)Listen for audio interruptions.
removeInterruptionListener(listener: AudioSessionInterruptionListener)Remove an interruption listener.
availableCategoriesGet the list of audio session categories available on the device.
availableModesGet the list of audio session modes available on the device.
isOtherAudioPlayingCheck if other audio is currently playing on the device.
secondaryAudioShouldBeSilencedHintCheck if secondary audio should be silenced.
allowHapticsAndSystemSoundsDuringRecordingCheck if haptics and system sounds are allowed during recording.
prefersNoInterruptionsFromSystemAlertsCheck if the session prefers no interruptions from system alerts.
setActive(active: boolean, options?: AudioSessionSetActiveOptions[])Activate or deactivate the shared audio session with optional options.
active: Set to true to activate the session, false to deactivate it.options: An array of optional activation options, such as 'interruptSpokenAudioAndMixWithOthers'.setAllowHapticsAndSystemSoundsDuringRecording(value: boolean)Enable or disable haptics and system sounds during recording.
setPrefersNoInterruptionsFromSystemAlerts(value: boolean)Set the preference for no interruptions from system alerts.
Optional activation options:
'notifyOthersOnDeactivation': Notify other audio sessions when deactivating the shared audio session.Defines the session's audio category:
'ambient': Ambient audio, such as background music or ambient sounds.'multiRoute': Multi-route audio, such as routing distinct streams of audio data to different output devices at the same time.'playAndRecord': Play and record audio, such as voice chat or video conferencing.'playback': Playback audio, such as music or sound effects.'record': Recording audio, such as voice chat or video conferencing.'soloAmbient': Solo ambient audio, such as background music or ambient sounds.Optional behaviors for audio categories:
'mixWithOthers': Mix with other audio sessions.'duckOthers': Duck other audio sessions.'interruptSpokenAudioAndMixWithOthers': Interrupt spoken audio and mix with others.'allowBluetooth': Allow Bluetooth audio.'allowBluetoothA2DP': Allow Bluetooth A2DP audio.'allowAirPlay': Allow AirPlay audio.'defaultToSpeaker': Default to speaker, even if headphones are connected.'overrideMutedMicrophoneInterruption': Override muted microphone interruption.Specifies the session's mode:
'default': Default mode.'gameChat': Game chat mode.'measurement': Measurement mode, such as audio input or output.'moviePlayback': Movie playback mode, such as movie content.'spokenAudio': Spoken audio mode, such as voice chat.'videoChat': Video chat mode, such as video conferencing.'videoRecording': Video recording mode, such as video conferencing.'voicePrompt': Voice prompt mode, such as text-to-speech.Specifies the type of interruption:
'began''ended''unknown'This interface offers extensive control over audio session management in Scripting, making it suitable for building audio-heavy script like music players and video conferencing tools.